define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'annalgame/annalchange/index',
                    add_url: 'annalgame/annalchange/add',
                    edit_url: 'annalgame/annalchange/edit',
                    del_url: 'annalgame/annalchange/del',
                    multi_url: 'annalgame/annalchange/multi',
                    table: 'v_annal_game',
                }
            });

          var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {field: 'uid', title: __('Uid')},
                        {field: 'nickname', title: __('Nickname')},
                        {field: 'sex', title: __('Sex'),searchable:false},
                        {field: 'level', title: __('Level'),searchable:false},
                        {field: 'kinId', title: __('KinId'), searchList: $.getJSON('annalgame/annalroom/getOnGameList?type=1'), style: 'min-width:100px;'},
                        {field: 'roomid', title: __('Roomid')},
                        {field: 'win', title: __('Win'),searchable:false},
                        {field: 'createtime', title: __('Createtime'),formatter: Table.api.formatter.datetimes, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD HH:mm:ss"', style: 'min-width:90px;'},
                        {field: 'gametime', title: __('Gametime'),searchable:false},
                        {field: 'ctype', title: __('Ctype'), searchList: {'1':'积分', '2': '金币'}},
                        {field: 'changes', title: __('Changes'),searchable:false},
                    ]
                ],
                
	            onLoadSuccess: function (data) {
	            	if(data.map == 1){
						$("#gametimenum").html('查询条件下总游戏时长：' + data.gametimenum);
					}else{
						$("#gametimenum").html('系统总游戏时长：' + data.gametimenum);
					}
                	$("#gametimenum").show();
	            }
            
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});